<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>状态动画</title>
  </head>
  <body>
    <script src="https://unpkg.com/vue@next"></script>
    <div id="root"></div>

    <script>
      const app = Vue.createApp({
        data() {
          return {
            number: 1,
            animateNumber: 1,
          };
        },

        methods: {
          handleClick() {
            this.number = 10;

            if (this.animateNumber < this.number) {
              const timer = setInterval(() => {
                this.animateNumber += 1;

                if (this.animateNumber === 10) {
                  clearInterval(timer);
                }
              }, 100);
            }
          },
        },

        template: `
                    <div>{{animateNumber}}</div>
                    <button @click="handleClick">按钮</button>  
                `,
      });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
